using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace FirebirdDAO
{
    ///<summary>
    /// DAO Class for the Customer table.
    ///</summary>
    public class CUSTOMER : Entity
    {
        private Int32 _CUST_NO;
        private String _CUSTOMER;
        private String _CONTACT_FIRST;
        private String _CONTACT_LAST;
        private String _PHONE_NO;
        private String _ADDRESS_LINE1;
        private String _ADDRESS_LINE2;
        private String _CITY;
        private String _STATE_PROVINCE;
        private String _COUNTRY;
        private String _POSTAL_CODE;
        private String _ON_HOLD;

        ///Default constructor
        public CUSTOMER()
        {

        }

        /// <summary>
        /// Constructor for joins. 
        /// Available CHILD tables to join with:
        ///    - Sales ( Sales_integ_77 )
        /// Available PARENT tables to join with:
        ///    - Country
        /// </summary>
        public CUSTOMER(bool Flat, params Entity[] entities)
            : this()
        {
            foreach (Entity entity in entities)
            {
                string[] entityParts = entity.GetType().ToString().Split('.');
                string entityName = entityParts[entityParts.Length - 1];
                PropertyInfo pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, new EntityCollection(entity), null);
                }
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
            }
            SetFlat(Flat);
        }

        ///Constructor for Joins with flat hierarchy
        public CUSTOMER(params Entity[] entities)
            : this(true, entities)
        {
        }

        ///<summary>
        /// Property for column Cust_no.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        public Int32 Cust_no
        {
            get
            {
                return _CUST_NO;
            }
            set
            {
                _CUST_NO = value;
            }
        }
        ///<summary>
        /// Property for column Customer.
        ///</summary>
        [IsNotNullable]
        [MaxLength(25)]
        public String Customer
        {
            get
            {
                return _CUSTOMER;
            }
            set
            {
                _CUSTOMER = value;
            }
        }
        ///<summary>
        /// Property for column Contact_first.
        ///</summary>
        [MaxLength(15)]
        public String Contact_first
        {
            get
            {
                return _CONTACT_FIRST;
            }
            set
            {
                _CONTACT_FIRST = value;
            }
        }
        ///<summary>
        /// Property for column Contact_last.
        ///</summary>
        [MaxLength(20)]
        public String Contact_last
        {
            get
            {
                return _CONTACT_LAST;
            }
            set
            {
                _CONTACT_LAST = value;
            }
        }
        ///<summary>
        /// Property for column Phone_no.
        ///</summary>
        [MaxLength(20)]
        public String Phone_no
        {
            get
            {
                return _PHONE_NO;
            }
            set
            {
                _PHONE_NO = value;
            }
        }
        ///<summary>
        /// Property for column Address_line1.
        ///</summary>
        [MaxLength(30)]
        public String Address_line1
        {
            get
            {
                return _ADDRESS_LINE1;
            }
            set
            {
                _ADDRESS_LINE1 = value;
            }
        }
        ///<summary>
        /// Property for column Address_line2.
        ///</summary>
        [MaxLength(30)]
        public String Address_line2
        {
            get
            {
                return _ADDRESS_LINE2;
            }
            set
            {
                _ADDRESS_LINE2 = value;
            }
        }
        ///<summary>
        /// Property for column City.
        ///</summary>
        [MaxLength(25)]
        public String City
        {
            get
            {
                return _CITY;
            }
            set
            {
                _CITY = value;
            }
        }
        ///<summary>
        /// Property for column State_province.
        ///</summary>
        [MaxLength(15)]
        public String State_province
        {
            get
            {
                return _STATE_PROVINCE;
            }
            set
            {
                _STATE_PROVINCE = value;
            }
        }
        ///<summary>
        /// Property for column Country.
        ///</summary>
        [MaxLength(15)]
        public String Country
        {
            get
            {
                return _COUNTRY;
            }
            set
            {
                _COUNTRY = value;
            }
        }
        ///<summary>
        /// Property for column Postal_code.
        ///</summary>
        [MaxLength(12)]
        public String Postal_code
        {
            get
            {
                return _POSTAL_CODE;
            }
            set
            {
                _POSTAL_CODE = value;
            }
        }
        ///<summary>
        /// Property for column On_hold.
        ///</summary>
        [MaxLength(1)]
        public String On_hold
        {
            get
            {
                return _ON_HOLD;
            }
            set
            {
                _ON_HOLD = value;
            }
        }

        #region Sales
        private EntityCollection _Sales;
        ///<summary>
        /// Related table Sales as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Sales), "Sales")]
        public EntityCollection Sales
        {
            get
            {
                return _Sales;
            }

            set
            {
                _Sales = value;
            }
        }
        private Sales _Sales_;
        ///<summary>
        /// Related table Sales as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Sales Sales_
        {
            get
            {
                return _Sales_;
            }

            set
            {
                _Sales_ = value;
            }
        }
        #endregion
        //#region Country
        //private EntityCollection _Country;
        ///<summary>
        /// Related table Country as a collection for hierarchical retrieval.
        ///</summary>
        //[NotInTable]
        //[TypeContainedAttribute(typeof(Country), "Country")]
        //public EntityCollection Country
        //{
        //    get
        //    {
        //        return _Country;
        //    }

        //    set
        //    {
        //        _Country = value;
        //    }
        //}
        //private Country _Country_;
        /////<summary>
        ///// Related table Country as a single object for flat retrieval.
        /////</summary>
        //[NotInTable]
        //public Country Country_
        //{
        //    get
        //    {
        //        return _Country_;
        //    }

        //    set
        //    {
        //        _Country_ = value;
        //    }
        //}
        //#endregion
        /// <summary>
        /// Gets join for current entity and table.
        /// </summary>
        /// <param name="tableName">Table to join with entity.</param>
        /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
            if (string.Compare(tableName, "Sales", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Cust_no");
                right.Add(GetType().Name + ".Cust_no");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Country", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Country");
                right.Add(GetType().Name + ".Country");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            return null;
        }
    }
}


